#include "Timer.h"
//--------------------------------------------------------------------------------
ns::Timer::Timer(){
	deltaTime = measureFPSSample = frameCounter = FPS  = 0;
}
//--------------------------------------------------------------------------------
void ns::Timer::FirstMeasure(){
	QueryPerformanceFrequency(&frecuency);
	QueryPerformanceCounter(&lastTime);
}
//--------------------------------------------------------------------------------
void ns::Timer::Measure(){
	//realizo la medicion del frame actual
	QueryPerformanceCounter(&actualTime);

	//calculo el tiempo actual en milisegundos
	deltaTime = static_cast<double>((actualTime.QuadPart - lastTime.QuadPart) * 1000.0f / frecuency.QuadPart);

	//tomo el estado del tiempo actual
	lastTime = actualTime;

	//actualizo el estado de los frames por segundo
	frameCounter++;
	measureFPSSample += deltaTime;

	if (measureFPSSample >= 1000)
	{
		measureFPSSample -= 1000;
		FPS = frameCounter;
		frameCounter = 0;
	}
}
//--------------------------------------------------------------------------------
unsigned int ns::Timer::getFPS(){
	return FPS;
}
//--------------------------------------------------------------------------------
float ns::Timer::getDT(){
	return (float)deltaTime;
}
//--------------------------------------------------------------------------------